package com.linchong.concurrency.chapter2;

import lombok.Data;

/**
 * @Author:linchong
 * @CreateTime:2019-12-31 15:14
 * @Description:策略模式，税率计算
 */
@Data
public class TaxCalaculator {
	private final double salary;
	private final double bonus;
	/*1.加入计算税率的方法*/
	private CalculatorStrategy calculatorStrategy;


	/*public TaxCalaculator(double salary,double bonus){
		this.salary = salary;
		this.bonus = bonus;
	}*/

	public TaxCalaculator(double salary, double bonus, CalculatorStrategy calculatorStrategy) {
		this.salary = salary;
		this.bonus = bonus;
		this.calculatorStrategy = calculatorStrategy;
	}

	//old
	/*protected double calcTax(){
		return 0.0d;
	}*/

	/**
	 * 2.利用传入的税率计算方法计算
	 **/
	protected double calcTax() {
		return calculatorStrategy.calculate(salary, bonus);
	}

	public double calculate() {
		return calcTax();
	}
}
